import React from 'react'
import './user.css';
    
export default class User extends React.Component {
    delPost(element){
        console.log(element.element.Uid)
        fetch("http://localhost:8080/p",{
            method:'post',
            headers:{
                'Accept':'application/json,text/plain,*/*',/* 格式限制：json、文本、其他格式 */
                'Content-Type':'application/x-www-form-urlencoded'/* 请求内容类型 */
            },
            body:`id=${element.element.Uid}`})
            window.location.reload()
    }
    constructor(){
        super()
        this.state={
          banners:[],
        }
      }
      componentDidMount(){
        fetch("http://localhost:8080/o")
        .then(res => res.json())
        .then(data => {
            this.setState({
                banners:data.data
            })
        })
    }
    render() {
        return (
            <div>
                {
                this.state.banners.map((element,index)=>{
                    return(
                    <ul  className="index">
                        {
                             <li key={index}>
                                <div>用户id：{element.Uid} 头像：<img src={element.Uimage} alt="" className="image"/> 用户名：{element.Uname} 电话：{element.Uphone}
                                &nbsp; &nbsp; &nbsp; &nbsp;<button onClick={()=>this.delPost({element})}>删除</button></div>
                            </li>
                        }
                    </ul>   
                       
                    )
                })
                }
            </div>
        )
    }
}
    
